package com.kitty.game.pet.handler.upgrade;

import com.kitty.common.utils.SpringUtils;
import com.kitty.game.equip.message.RespNotifyMiscEx;
import com.kitty.game.equip.model.RoleEquip;
import com.kitty.game.pet.message.RespForgetPetSkill;
import com.kitty.game.pet.model.Pet;
import com.kitty.game.role.model.Role;
import com.kitty.mina.message.MessagePusher;
import org.springframework.stereotype.Component;

/**宠物遗忘技能*/
@Component
public class PetForgetHandler extends UpgradePetHandler {


    @Override
    public String acceptUpgradePet(Role role, Pet pet, String ids, String itemPos, String costType, String otherPetPos) {
        logger.error("宠物顿悟{},物品id{},物品位置{},{},{}",pet.getName(),ids,itemPos,costType,otherPetPos);
        RoleEquip roleEquip = equipService.getRoleEquipByPos(role, Short.parseShort(itemPos));
        if (roleEquip == null) {
            return ERROR_ITEM;
        }
        if (!roleEquip.getName().equals("宠物顿悟丹")){
            return ERROR_ITEM;
        }
        equipService.delEquipNum(role, roleEquip, 1);
        int skillId = Integer.parseInt(costType);
        pet.getSkillBox().getSkills().remove(skillId);
        role.save();
        MessagePusher.pushMessage(role,new RespNotifyMiscEx("遗忘成功"));
        SpringUtils.getPetService().loadPet(role,pet);
        RespForgetPetSkill respForgetPetSkill = new RespForgetPetSkill();
        respForgetPetSkill.setMonsterId(pet.getId());
        respForgetPetSkill.setFlag((byte) 2);
        respForgetPetSkill.setSkillId((short) skillId);
        MessagePusher.pushMessage(role,respForgetPetSkill);
        return null;
    }
}
